package com.example.demo.framework.interceptors;

import com.example.demo.framework.filters.tracer.TraceConst;
import com.example.demo.framework.filters.tracer.TraceInfo;
import com.example.demo.framework.utils.TraceUtils;
import feign.RequestInterceptor;
import feign.RequestTemplate;

/**
 * @Auther: miaoguoxin
 * @Date: 2020/3/20 14:32
 * @Description:
 */

public class FeignTraceInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        TraceInfo traceInfo = TraceUtils.get();
        if (traceInfo != null) {
            requestTemplate.header(TraceConst.TRACE_ID,traceInfo.getTraceId());
            requestTemplate.header(TraceConst.SERVICE_ID,traceInfo.getServiceId());
            requestTemplate.header(TraceConst.REQUEST_URI,traceInfo.getUri());
        }
    }
}
